4
4
.
.
2
2
.
.
9
9
S
S
u
u
r
r
f
f
a
a
c
c
e
e
I
I
n
n
f
f
o
o
Surface is Container View which can have only a single Child View.
You can use it to set background of included child.
Syntax
import androidx.compose.material.Surface
Surface {
Text("Text")
}
E
E
x
x
a
a
m
m
p
p
l
l
e
e
In this example we create Surface View with a single Text View.
MainActivity.kt
package com.example.testcompose
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.Text
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.Surface
import androidx.compose.ui.*
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.unit.dp
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Box(Modifier.fillMaxSize()) {
Surface(
modifier = Modifier.preferredSize(100.dp).align(Alignment.Center),
shape = CircleShape,
color = Color.Red
) {
Text(text = "Some text goes here")
}
}
}
}
}
Output